home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / SDKs / Word Services SDK 1.0.6 / Writeswell Jr 1.2.1 Sources ƒ / Writeswell Jr. Source / InitWWJr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-09-11  |  3.0 KB  |  153 lines  |  [TEXT/KAHL]

  1. /* InitWWJr.c
  2.  * Initialization code for Writeswell Jr.
  3.  *
  4.  * ©1992 Working Software, Inc.
  5.  * This source code is copyrighted.  Permission is granted to use the Word Services
  6.  * portion of the Writeswell Jr. source code in your own programs, but you 
  7.  * may not distribute the Writeswell Jr. word-processor code as a 
  8.  * commercial product.  If you modify the code, please do not call it 
  9.  * Writeswell Jr. (or Writeswell.)  This will ensure that people understand the 
  10.  * program and don’t have to deal with a number of different versions with 
  11.  * who-knows-what going on in the code.
  12.  * 
  13.  * Writeswell Jr. and Writeswell are trademarks of Working Software, Inc.
  14. */
  15.  
  16. #include <EPPC.h>
  17. #include <AppleEvents.h>
  18. #include "GenHandlers.h"
  19. #include "AppEvents.h"
  20. #include "InitMenu.h"
  21. #include "Gripe.h"
  22. #include "AEObj.h"
  23. #include "MyFiles.h"
  24. #include "InitWWJr.h"
  25.  
  26. OSErr CheckApplParams( SFReply *replyPtr );
  27.  
  28. OSErr InitForSystem7( void )
  29. {
  30.     OSErr    err;
  31.  
  32.     PutUpSys7Menus();
  33.  
  34.     if ( err = InitReqHandlers() )
  35.         return err;
  36.  
  37.     if ( err = InitGenericHandlers() )
  38.         return err;
  39.  
  40.     if ( err = InitAEObjStuff() )
  41.         return err;
  42.     
  43.     return noErr;
  44. }
  45.  
  46. OSErr TearDown( void )
  47. {
  48.     OSErr    err;
  49.  
  50.     // The particular routines we call here are only for PowerPC, but
  51.     // the function could be used in general for any case of termination.
  52.     
  53. #ifdef GENERATINGCFM
  54.     err = TearDownReqHandlers();
  55.     if ( err )
  56.         return err;
  57.     
  58.     err = TearDownGenerichandlers();
  59.     if ( err )
  60.         return err;
  61.     
  62.     err = TearDownAEObjStuff();
  63.     if ( err )
  64.         return err;
  65.     
  66. #endif
  67.     return noErr;
  68. }
  69.  
  70. #ifndef GENERATINGCFM
  71. // This stuff won't compile under PowerPC
  72.  
  73. OSErr InitForSystem6( void )
  74. {
  75.     OSErr    err;
  76.     SFReply    reply;
  77.  
  78.     PutUpSys6Menus();
  79.     
  80.     CheckApplParams( &reply );
  81.  
  82.     if ( reply.good ){
  83.         err = MyOpenSfFile( &reply );
  84.     }else{
  85.         err = MakeNewWindow();
  86.     }
  87.     
  88.     return err;
  89. }
  90.  
  91. OSErr CheckApplParams( SFReply *replyPtr )
  92. {
  93.     short            message;
  94.     short            count;
  95.     short            i;
  96.     AppFile            file;
  97.     short            vRef;
  98.     ParamBlockRec    fPB;
  99.     OSErr            err;
  100.  
  101.     replyPtr->good = false;
  102.  
  103.     CountAppFiles(&message,&count);
  104.     if (!count)
  105.         return noErr;
  106.  
  107.     err = GetVol(0L,&vRef);
  108.     if ( err ){
  109.         Gripe( "\pGetVol failed" );
  110.         return err;
  111.     }
  112.  
  113.  
  114.     /* Loop through all the files that were selected on the desktop,
  115.        skipping all that don't have a type of 'TEXT' or 'ttro' */
  116.     for (i = 1; i <= count; i++)
  117.     {
  118.         GetAppFiles(i, &file);
  119.  
  120.         /* If it’s not a file type we can open, skip it */
  121.         switch ( file.fType ){
  122.             case 'TEXT':
  123.             case 'ttro':
  124.  
  125.                 fPB.fileParam.ioCompletion = (IOCompletionUPP)NULL;
  126.                 fPB.fileParam.ioNamePtr = (StringPtr)NULL;
  127.                 fPB.fileParam.ioVRefNum = file.vRefNum;
  128.                 
  129.                 err = PBSetVol( &fPB, false );
  130.                 if ( err ){
  131.                     Gripe( "\pPBSetVol failed in MyOpenSpecFile" );
  132.                     return err;
  133.                 }
  134.     
  135.                 replyPtr->vRefNum = file.vRefNum;
  136.                 replyPtr->fType = file.fType;
  137.                 replyPtr->version = file.versNum;
  138.                 BlockMove( file.fName, replyPtr->fName, (file.fName)[0] + 1 );
  139.                 replyPtr->copy = false;
  140.                 replyPtr->good = true;
  141.                 
  142.                 return noErr;
  143.                 break;
  144.  
  145.             default:
  146.                 ClrAppFiles(i);
  147.                 break;
  148.         }
  149.     }
  150.  
  151.     return noErr;
  152. }
  153. #endif